﻿using SqlKata.Compilers;
using SqlKata.Execution;
using System;

namespace Kele.Repository
{

    public class QFactory : IDisposable
    {
        public QueryFactory DB { get; }

        public QFactory(IDatabase database)
        {
            DB = new QueryFactory(database.GetConnection(), new MySqlCompiler());
        }

        /// <inheritdoc/>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (this.DB.Connection != null)
                    {
                        this.DB.Connection.Dispose();
                        this.DB.Connection = null;
                    }
                }

                disposedValue = true;
            }
        }
    }
}